<template>
	<view class="index">
		<view class="swiper-wrap">
			<swiper v-bind:style="{height:swiperHeight+'px'}" class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay"
			 :interval="interval" :duration="duration">
				<swiper-item v-for="item,index in bannerList">
					<view class="swiper-item">
						<img class="banner-img" :src="item.imgSrc" mode="">
					</view>
				</swiper-item>
			</swiper>
		</view>

		<view class="content">
			<view class="content-1">
				<div v-on:click="goDetail(item._id)" v-for="item,index in recommend" class="content-1-item">
					<img class="big-img" :src="item.image" alt="">
					<p class="title-p">{{item.name}}</p>
					<p class="msg-p">￥
						<span class="now-price">{{item.nowPrice}}</span>
						<span class="old-price">￥{{item.oldPrice}}</span>
					</p>
				</div>
			</view>
		</view>
	</view>

</template>

<script>
	import URL from '../../common/util.js'
	export default {
		data() {
			return {
				background: ['color1', 'color2', 'color3'],
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				swiperHeight: 0,
				bannerList: [{
						imgSrc: "http://images.baixingliangfan.cn/compressedPic/20180415115515_7254.jpg"
					},
					{
						imgSrc: "http://images.baixingliangfan.cn/compressedPic/20180415115515_7254.jpg"
					},
					{
						imgSrc: "http://images.baixingliangfan.cn/compressedPic/20180415115515_7254.jpg"
					},
					{
						imgSrc: "http://images.baixingliangfan.cn/compressedPic/20180415115515_7254.jpg"
					}
				],
				recommend: [],
				err: ""
			}
		},
		onLoad() {
			this.getGoods();

		},
		onShow() {
			
		},
		onReady() {
			var bannerImg = uni.createSelectorQuery().select(".swiper .swiper-item .banner-img");
			bannerImg.boundingClientRect((data) => {
				this.swiperHeight = data.height;
			}).exec();
		},
		methods: {
			getGoods() {
				console.log(this.$Interface.index)
				this.$Interface.goods.goodsList((res) => {
					console.log(res)
					this.recommend = res.data.goods;
				})
			},
			goDetail(goodsId) {
				// uni.navigateTo({
				// 	url: '/pages/prod-detail/index?goodsId=' + goodsId
				// });
			},
		}
	}
</script>

<style lang="scss" scoped="true">
	.index {
		color: $uni-color-primary;
	}

	.swiper {
		height: 300upx;
	}

	.swiper-wrap {
		img {
			width: 100%;
		}
	}

	.content {
		.content-1 {
			display: flex;
			flex-direction: row;
			flex-wrap: wrap;

			.content-1-item {
				width: 50%;
			}
		}
	}

	.big-img {
		width: 368upx;
		height: 368upx;
	}

	.title-p {
		margin: 0 auto;
		text-overflow: ellipsis;
		padding: 10upx 0;
		width: 340upx;
		white-space: nowrap;
		overflow: hidden;
		font-size: 25upx;
		font-family: MicrosoftYaHei;
		font-weight: 400;
		color: rgba(99, 99, 99, 1);

		img {
			width: 28upx;
			height: 28upx;
			position: relative;
			top: 5upx;
		}
	}

	.msg-p {
		font-size: 21upx;
		font-family: MicrosoftYaHei;
		font-weight: 400;
		color: rgba(255, 36, 36, 1);
		padding-top: 10upx;
		padding: 10upx 10upx 0;

		.now-price {
			font-size: 33upx;
		}

		.old-price {
			text-decoration: line-through;
			color: #C5C5C5;
		}

		.buy-num {
			color: #C5C5C5;
			float: right;
			margin-top: 10upx;
		}
	}
</style>
